package cn.xsly.ymcc.web.controller;

import cn.xsly.ymcc.config.AjaxResult;
import cn.xsly.ymcc.config.Base64;
import cn.xsly.ymcc.config.RedisCache;
import cn.xsly.ymcc.config.RuoYiConfig;
import cn.xsly.ymcc.constants.Constants;
import cn.xsly.ymcc.dto.UserRegisterDto;
import cn.xsly.ymcc.result.JSONResult;
import cn.xsly.ymcc.service.VerifycodeService;
import cn.xsly.ymcc.util.StrUtils;
import cn.xsly.ymcc.util.VerifyCodeUtils;
import com.google.code.kaptcha.Producer;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.IOException;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private VerifycodeService verifycodeService;

    /*@Autowired
    private RedisCache redisCache;*/
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

   /* //图形验证码
    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey){
       String imgCode=verifycodeService.getImageCode(imageCodeKey);
       return JSONResult.success(imgCode);
    }*/

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult getImgCode(@PathVariable("imageCodeKey") String imageCodeKey) {
        String imgCode=verifycodeService.getImgCode(imageCodeKey);

        return JSONResult.success(imgCode);
    }

    //手机验证码
    @PostMapping("/sendSmsCode")
    public JSONResult smsCode(@RequestBody @Valid UserRegisterDto dto) {
        verifycodeService.sendSmsCode(dto);
        return JSONResult.success();
    }
}
